<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<html>
<head>
<title>收件箱</title>
<script type="text/javascript">
	var $grid;
	$(function() {
		$grid = $("#grid").datagrid($.extend(datagridOption, {
			title : "收件箱",
			url : "${ctx}/basic/notifyInfo/receiver_dataGrid",
			columns : [ [ {
				field : 'ck',
				checkbox : true
			}, {
				field : 'sender',
				title : '发件人',
				sortable : true,
				formatter : function(value, row, index) {
					if (row.attribute == 1) {
						return value ? "<b>" + value.trueName + "</b>" : "";
					} else {
						return value ? value.trueName : "";
					}
				}
			}, {
				field : 'title',
				title : '标题',
				sortable : true
			}, {
				field : 'sendTime',
				title : '发送时间',
				sortable : true
			}, {
				field : 'attribute',
				title : '状态',
				sortable : true,
				formatter : function(value, row, index) {
					return value == 1 ? "未读" : (value == 0 ? "已读" : "草稿");
				}
			}, {
				field : 'action',
				title : '操作',
				align : 'center',
				width : 280 ,
				formatter : function(value, row, index) {
					var result = "<button type='button' class='btn btn-primary' href='#' onclick='view(\"" + row.id + "\")'> <span class='glyphicon glyphicon-search'></span> 查看</button> ";
					result += "<button type='button' class='btn btn-primary' href='#' onclick='reply(\"" + row.id + "\")'><span class='glyphicon glyphicon-envelope'></span> 回复</button> ";
					result += "<button type='button' class='btn btn-primary' href='#' onclick='transmit(\"" + row.id + "\")'><span class='glyphicon glyphicon-repeat'></span> 转发</button> ";
					result += "<button type='button' class='btn btn-danger' href='#' onclick='deleteNotify(\"" + row.id + "\")'><span class='glyphicon glyphicon-minus'></span> 删除</button>";
					return result;
				}
			} ] ],
			onLoadSuccess : function(data) {
				$('.view-btn').linkbutton({
					iconCls : 'icon-cologne-featured',
					plain : true
				});
				$('.reply-btn').linkbutton({
					iconCls : 'icon-cologne-comment',
					plain : true
				});
				$('.transmit-btn').linkbutton({
					iconCls : 'icon-hamburg-exchange',
					plain : true
				});
				$('.delete-btn').linkbutton({
					iconCls : 'icon-hamburg-busy',
					plain : true
				});
			}
		}));

		$grid.datagrid('enableFilter');
		$("#search").click(function() {
			$grid.datagrid('load', $("#tt").form("getData"));
		});
	});
	function view(id) {
		window.parent.addTab("notifiInfoDetail", "邮件查看", "${ctx}/basic/notifyInfo/detail/" + id);
	}
	function reply(id) {
		window.parent.addTab("notifyInfoReply", "回复邮件", "${ctx}/basic/notifyInfo/create?id=" + id + "&action=reply");
	}
	function transmit(id) {
		window.parent.addTab("notifyInfoTransmit", "转发邮件", "${ctx}/basic/notifyInfo/create?id=" + id + "&action=transmit");
	}
	function deleteNotify(id) {
		$.messager.confirm("您确定要进行该操作？", function(c) {
			if (c) {
				$.get("${ctx}/basic/notifyInfo/recover/" + id, function(result) {
					$.messager.show({
						msg : result.msg,
						icon : "info",
						position : "bottomRight"
					});
					if (result.success) {
						$grid.datagrid("load");
					}
				}, 'json');
			}
		});
	}
</script>
</head>

<body>
	<div data-options="region:'center',fit:true,border:false">
		<table id="grid">
		</table>
	</div>
	<div id="tt" class="row">
		<div class="col-md-12">
			<form class="form-grid-search form-inline">
				<div class="form-group">
					<span>标题：</span> <input type="text" class="form-control"
						name="search_LIKE_title"/> <span>发件人：</span> <input
						type="text" class="form-control"
						name="search_LIKE_sender.trueName"/>
				</div>
				<button type="button" id="search" class="btn btn-primary">
					<span class="glyphicon glyphicon-search"></span> 查询
				</button>
			</form>
		</div>
	</div>
</body>
</html>
